//
//  MILSelectedRingsOfBellViewController.m
//  MicrowaveInteractionLight
//
//  Created by maple on 2016/12/17.
//  Copyright © 2016年 maple. All rights reserved.
//

#import "MILSelectedRingsOfBellViewController.h"

@interface MILSelectedRingsOfBellViewController ()
@property (weak, nonatomic) IBOutlet UITableView *myTableView;
//铃声选中的状态
@property(nonatomic,strong)NSMutableArray *mySelectedRingsStatusMutableArray;
//铃声选中的下标
@property(nonatomic,assign)NSInteger selectedIndex;
@end

@implementation MILSelectedRingsOfBellViewController
#pragma mark -- 懒加载
- (NSMutableArray *)mySelectedRingsStatusMutableArray
{
    if (!_mySelectedRingsStatusMutableArray)
    {
        _mySelectedRingsStatusMutableArray = [NSMutableArray arrayWithArray:@[@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0"]];
    }
    
    return _mySelectedRingsStatusMutableArray;
}
#pragma mark -- UI
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //初始化UI
    [self initMILSelectedRingsOfBellView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)refreshBaseControlValue
{
    [self setNavigationBarTitle:@"选择铃声"];
}

//初始化UI
- (void)initMILSelectedRingsOfBellView
{
    self.selectedIndex = 50;//大于10 作为判断条件
}

#pragma mark UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 10;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (!cell)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    }
    cell.backgroundColor = [UIColor whiteColor];
    cell.textLabel.text = [NSString stringWithFormat:@"%@%ld",@"铃声",(long)indexPath.section+1];
    if (self.selectedIndex < 50 && indexPath.section == self.selectedIndex)
    {
        UIImageView *myImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"xuanzhong9"]];
        cell.accessoryView = myImageView;
    }
    else
    {
        UIImageView *myImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"weixuanzhong"]];
        cell.accessoryView = myImageView;
    }
    
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%ld",(long)indexPath.section);
    self.selectedIndex = indexPath.section;
    //传到上一级界面
    [[NSNotificationCenter defaultCenter]postNotificationName:NOTIFICATION_SELECTEDRING object:self userInfo:@{@"ring":[NSString stringWithFormat:@"%ld",(long)self.selectedIndex+1]}];
    [tableView reloadData];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return   1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    
    return 1.5;
}



@end
